package game.view.component
{//game.view.component.AutoSelectView
	import com.base.event.ZooEvent;
	import com.greensock.TweenMax;
	
	import flash.events.*;
	import flash.geom.*;
	import flash.text.*;
	
	import game.model.GameData;
	import game.model.type.Enum;
	import game.model.type.NoticeCMD;
	import morn.App;
	import game.view.base.gamepanel.AutoSelectViewUI;
	public class AutoSelectView extends AutoSelectViewUI
	{
		private var autoBgXyList:Array=[0,21,42,63,84,105];
		
		public function AutoSelectView()
		{
			super();
		}
		override protected function initialize():void
		{
			super.initialize();
			autoLabel0.text='关闭自动跳跃';autoLabel2.text='自动跳至第2关';autoLabel3.text='自动跳至第3关';autoLabel4.text='自动跳至第4关';
			autoLabel5.text='自动跳至第5关';autoLabel6.text='自动跳至第6关';
			ZooMain.event.addEventListener(NoticeCMD.NOTICE_SRS_automatic_change,autoChange);
			autoLabel0.addEventListener(MouseEvent.CLICK,levelTxtClick);
			autoLabel2.addEventListener(MouseEvent.CLICK,levelTxtClick);
			autoLabel3.addEventListener(MouseEvent.CLICK,levelTxtClick);
			autoLabel4.addEventListener(MouseEvent.CLICK,levelTxtClick);
			autoLabel5.addEventListener(MouseEvent.CLICK,levelTxtClick);
			autoLabel6.addEventListener(MouseEvent.CLICK,levelTxtClick);
			openBtnBox.addEventListener(MouseEvent.CLICK,openBtnClick);
			openLabel.text='关闭自动跳跃';
			selectBox.visible=false;
		}
		private function autoChange(evt:ZooEvent):void{
			this.setSelect();
		}
		private function setSelect():void{
			if(GameData.instance.myLevelId>GameData.instance.automaticIndex){
				GameData.instance.automaticIndex=Enum.no_num;
			}
			if(GameData.instance.automaticIndex==Enum.no_num){
				//autoBgimg.url='png.img.game.6666';
				autoBgimg.y=autoBgXyList[0];
				openLabel.text='关闭自动跳跃';
			}else{
				//autoBgimg.url='png.img.game.555';
				autoBgimg.y=autoBgXyList[GameData.instance.automaticIndex-1];
				openLabel.text='自动跳至第'+GameData.instance.automaticIndex+'关';
			}
			for(var i:int=2;i<7;i++){
				if(GameData.instance.myLevelId>i){
					this['autoLabel'+i].color=0xCCCCCC;
					this['autoLabel'+i].buttonMode=false;
				}else{
					this['autoLabel'+i].color=0xFFFFFF;
					this['autoLabel'+i].buttonMode=true;
				}
			}
			
		}
		private function levelTxtClick(evt:MouseEvent):void{
			evt.stopPropagation();
			var name:String=evt.target.name;
			var index:String=name.charAt(name.length-1);
			var level:int=int(index);
			trace('AutoSelectView levelTxtClick',evt.target.name,index);
			if(level==0){
				GameData.instance.automaticIndex=Enum.no_num;
				//selectBox.visible=false;
				//this.stage.removeEventListener(MouseEvent.CLICK,stageClick);
			}else{
				if(level>=GameData.instance.myLevelId){
					GameData.instance.automaticIndex=level;
				}
			}
			this.setSelect();
			selectBox.visible=false;
			this.stage.removeEventListener(MouseEvent.CLICK,stageClick);
		}
		private function stageClick(evt:MouseEvent):void{
			trace('AutoSelectView stageClick');
			selectBox.visible=false;
			this.stage.removeEventListener(MouseEvent.CLICK,stageClick);
		}
		
		private function stageTimeH():void{
			trace(this.autoBgXyList);
			this.stage.addEventListener(MouseEvent.CLICK,stageClick);
		}
		private function openBtnClick(evt:MouseEvent):void{
			selectBox.visible=!selectBox.visible;
			this.setSelect();
			if(selectBox.visible){
				App.timer.doOnce(400,this.stageTimeH);	
			}else{
				this.stage.removeEventListener(MouseEvent.CLICK,stageClick);
			}
		}
	}
}